<template>
  <div class="login-container">
    <!-- 背景装饰元素 -->
    <div class="bg-decoration"></div>

    <!-- 登录卡片 -->
    <div class="login-card">
      <div class="login-header">
        <!-- 系统图标 -->
        <div class="system-icon">
          <i class="el-icon-trophy"></i>
        </div>
        <h2 class="login-title">吉林油田公司科学技术奖网评系统</h2>
        <p class="login-subtitle">请输入您的评审编码进行验证</p>
      </div>

      <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
      >
        <el-form-item prop="judgeCode">
          <el-input
              v-model="loginForm.judgeCode"
              placeholder="请输入评审编码"
              prefix-icon="el-icon-lock"
              autocomplete="off"
              :disabled="loading"
              class="form-input"
          />
        </el-form-item>

        <el-form-item>
          <el-button
              type="primary"
              @click="handleLogin"
              style="width: 100%;"
              :loading="loading"
              class="login-btn"
          >
            验证并进入评审
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 页脚信息 -->
    <div class="login-footer">
      <p>© 2025 吉林油田公司科学技术奖网评系统 版权所有</p>
      <p>技术支持：地球物理勘探研究院</p>
<!--      <p class="footer-links">
        <a href="/help-page" class="footer-link" target="_blank">使用帮助</a>
        <span class="divider">|</span>
        <a href="#" class="footer-link">联系我们</a>
      </p>-->
    </div>
  </div>
</template>

<script>
import {authenticateJudge} from '@/api/judge'

export default {
  name: 'Auth',
  data() {
    return {
      loginForm: {
        judgeCode: ''
      },
      loginRules: {
        judgeCode: [
          {required: true, message: '请输入评审编码', trigger: 'blur'}
        ]
      },
      loading: false
    };
  },

  created() {
    // 检查是否有已过期的登录状态
    this.checkLoginExpiration();
  },

  methods: {
    // 检查登录是否过期
    checkLoginExpiration() {
      const loginTime = localStorage.getItem('loginTimestamp');
      if (loginTime) {
        // 计算是否超过1天(86400000毫秒)
        const now = new Date().getTime();
        if (now - parseInt(loginTime) > 86400000) {
          localStorage.removeItem('currentUser');
          localStorage.removeItem('loginTimestamp');
          this.$message.warning('登录已过期，请重新验证');
        } else {
          // 登录有效，直接跳转到评审页面
          this.$router.push('/review');
        }
      }
    },

    // 处理登录逻辑
    async handleLogin() {
      this.$refs.loginForm.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          try {
            const response = await authenticateJudge({
              judgeCode: this.loginForm.judgeCode
            });
            if (response.code === '200') {
              const authData = response.data;
              const userInfo = {
                id: authData.id,
                name: authData.expertName,
                expertId: authData.expertId,
                specialty: authData.specialty
              };

              // 存储用户信息和登录时间戳
              localStorage.setItem('currentUser', JSON.stringify(userInfo));
              localStorage.setItem('loginTimestamp', new Date().getTime().toString());

              this.$message.success(`登录成功，欢迎 ${userInfo.name} 评委`);

              // 登录成功后跳转到评审页面，并携带时间范围参数
              setTimeout(() => {
                this.$router.push({
                  path: '/review',
                  query: {
                    startTime: authData.reviewStartTime,
                    endTime: authData.reviewEndTime
                  }
                });
              }, 1000);
            } else {
              this.$message.error(response.msg || '验证失败');
            }
          } catch (error) {
            console.error('登录失败', error);
            this.$message.error('登录失败，请重试');
          } finally {
            this.loading = false;
          }
        }
      });
    }
  }
};
</script>

<style scoped>
/* 主容器样式 */
.login-container {
  min-height: 100vh;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  padding: 20px;
}

/* 背景装饰 */
.bg-decoration {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 30% 107%, #3256a8 0%, #1a3670 90%);
  opacity: 0.05;
  transform: scale(1.5);
  z-index: 1;
}

/* 登录卡片样式 */
.login-card {
  width: 420px;
  padding: 40px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
}

/* 登录头部样式 */
.login-header {
  text-align: center;
  margin-bottom: 35px;
}

/* 系统图标 */
.system-icon {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: white;
  font-size: 32px;
  box-shadow: 0 4px 15px rgba(30, 64, 175, 0.25);
}

/* 标题样式 */
.login-title {
  font-size: 26px;
  color: #1e293b;
  margin-bottom: 12px;
  font-weight: 600;
}

.login-subtitle {
  font-size: 15px;
  color: #64748b;
  line-height: 1.6;
}

/* 表单样式 */
.login-form {
  margin-top: 25px;
}

/* 输入框样式 */
.form-input {
  height: 50px;
  font-size: 15px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
}
/* 去掉内部 input 的边框和圆角 */
.form-input /deep/ .el-input__inner {
  border: none;
  border-radius: 0;
  box-shadow: none; /* 聚焦时也不显示内阴影 */
  height: 50px;     /* 保持你外层设定的高度 */
  font-size: 15px;
}

.form-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 按钮样式 */
.login-btn {
  height: 50px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 8px;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  border: none;
  transition: all 0.3s ease;
}

.login-btn:hover {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.login-btn:active {
  transform: translateY(0);
}

/* 页脚样式 */
.login-footer {
  margin-top: 30px;
  color: #94a3b8;
  font-size: 13px;
  text-align: center;
  position: relative;
  z-index: 2;
}

.footer-links {
  margin-top: 10px;
}

.footer-link {
  color: #64748b;
  text-decoration: none;
  transition: color 0.2s ease;
  margin: 0 5px;
}

.footer-link:hover {
  color: #3b82f6;
  text-decoration: underline;
}

.divider {
  margin: 0 8px;
  color: #cbd5e1;
}

/* 响应式调整 */
@media (max-width: 480px) {
  .login-card {
    width: 100%;
    padding: 30px 25px;
  }

  .login-title {
    font-size: 22px;
  }
}
</style>
